package com.yq.testmodule.exoplayer

import android.os.Bundle
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity
import androidx.media3.common.MediaItem
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.ui.PlayerView
import com.alibaba.android.arouter.facade.annotation.Route
import com.yq.testmodule.R
import config.TEST_EXOOPlayer

@Route(path = TEST_EXOOPlayer)
class ExoplayerVideoListActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_test_exoplayer)
        val player = ExoPlayer.Builder(this).build()
        val player2 = ExoPlayer.Builder(this).build()
        val playerView = findViewById<PlayerView>(R.id.playerview)
        val playerView2 = findViewById<PlayerView>(R.id.playerview2)
        playerView.player = player
        playerView2.player = player2

        // Build the media item.
        val mediaItem = MediaItem.fromUri("http://poss-videocloud.cns.com.cn/oss/2023/08/09/chinanews/MEIZI_YUNSHI/onair/F3FECF11BFD5440688275F25A71150F2.mp4")
        // Set the media item to be played.
        player.setMediaItem(mediaItem)
        player2.setMediaItem(mediaItem)

        val btnPlayer = findViewById<Button>(R.id.btnPlayer)
        btnPlayer.setOnClickListener {

            // Prepare the player.
            player.prepare()
            // Start the playback.
            player.play()



            // Prepare the player.
            player2.prepare()
            // Start the playback.
            player2.play()
        }
    }
}